import 'package:http/http.dart' as http;
import 'dart:convert' as convert;
import 'response/chatInfo.dart';

class HttpRequest{

  static const String serverIp = "127.0.0.1";
  static const String serverPort = "9999";
  static const String host = "$serverIp:$serverPort";

  static Future<List<ChatInfo>> getChatInfo() async {
    var url = Uri.http(serverIp, "/chatInfoList");

    var response = await http.get(url);
    if(response.statusCode == 200 ){
      var jsonResp = convert.jsonDecode(response.body) as List<dynamic>;
      List<ChatInfo> res=[];
      for(var e in jsonResp) {
        var j = e as Map<String, dynamic>;
        res.add(ChatInfo.fromJson(j));
      }
      return res;
    } else {
      throw Exception("get chatInfo list error!");
    }
  }


}